import Vue from 'vue'
import VueRouter from 'vue-router'
import Main from '@c/main/Main'

Vue.use(VueRouter)

/**
 * 发红包页面
 */
function send(name)
{
  return {
    path: 'send/:type/:red_id',
    name: name,
    meta: {
      title: '发红包'
    },
    component: () => import('@/children/send/Send.vue')
  }
}

const routes = [
  {
    path: '/',
    name: '_home',
    redirect:'/home',
    component: Main,
    children: [
      {
        path: '/home',
        name: 'home',
        component: () => import('@v/home/Home.vue'),
        children: [
          {
            path: 'list',
            name: 'list',
            meta: {
              title: '红包列表'
            },
            component: () => import('@v/home/children/list/List.vue')
          },
          {
            path: 'record/:record_red_id',
            name: 'main-record',
            meta: {
              title: '红包领取记录'
            },
            component: () => import('@/children/record/Record.vue')
          },
          {
            path: 'form-list/:form_red_id',
            name: 'main-form-list',
            meta: {
              title: '红包填表数据'
            },
            component: () => import('@/children/form-list/FormList.vue')
          },
          {
            path: 'card-bag',
            name: 'main-card-bag',
            meta: {
              title: '卡券包'
            },
            component: () => import('@v/member/children/card-bag/CardBag.vue')
          },
          // 发红包
          send("home-send")
        ]
      },
      {
        path: '/member',
        name: 'member',
        component: () => import('@v/member/Member.vue'),
        children: [
            // 发红包
            send("member-send"),
            // 提现页面
            {
              path: 'deposit',
              name: 'deposit',
              meta: {
                title: '提现'
              },
              component: () => import('@v/member/children/deposit/Deposit.vue')
            },
            // 收入记录
            {
              path: 'income',
              name: 'income',
              meta: {
                title: '收入记录'
              },
              component: () => import('@v/member/children/income/Income.vue')
            },
            // 用户卡券包
            {
              path: 'card-bag',
              name: 'card-bag',
              meta: {
                title: '卡券包'
              },
              component: () => import('@v/member/children/card-bag/CardBag.vue')
            },
            // 我发的红包列表
            {
              path: 'me-red',
              name: 'me-red',
              meta: {
                title: '我的红包'
              },
              component: () => import('@v/member/children/me-red/MeRed.vue'),
              children: [
                //滚动红包列表
                {
                  path: 'me-red-scroll/:red_id',
                  name: 'me-red-scroll',
                  meta: {
                    title: '我的红包'
                  },
                  children: [
                    {
                      path: 'record/:record_red_id',
                      name: 'me-main-record',
                      meta: {
                        title: '红包领取记录'
                      },
                      component: () => import('@/children/record/Record.vue')
                    },
                    {
                      path: 'form-list/:form_red_id',
                      name: 'me-main-form-list',
                      meta: {
                        title: '红包领取记录'
                      },
                      component: () => import('@/children/form-list/FormList.vue')
                    },
                    {
                      path: 'card-bag',
                      name: 'me-main-card-bag',
                      meta: {
                        title: '卡券包'
                      }
                    }
                  ],
                  component: () => import('@v/member/children/me-red/children/red-scroll-list/RedScrollList.vue')
                },
                // 修改红包
                {
                  path: 'edit/:type/:red_id',
                  name: "edit",
                  meta: {
                    title: '修改红包'
                  },
                  component: () => import('@/children/send/Send.vue')
                }
              ]
            },
            // 员工管理
            {
              path: 'staff',
              name: 'staff',
              meta: {
                title: '员工管理'
              },
              component: () => import('@v/member/children/staff/Staff.vue')
            }
        ]
      }
    ]
  },
  {
    path: '*',
    name: 'error_404',
    component: () => import('@/views/error/Error_404.vue')
  },
  {
    path: '/error-408',
    name: 'error_408',
    component: () => import('@/views/error/Error_408.vue')
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if(to.meta.title){
    document.title = to.meta.title
  } else {
    document.title = window.cool.app_name
  }
  next()
})

export default router
